package server.fassade;

import java.util.HashMap;
import java.util.Map;


/*
 * Note: this class is nowhere near Thread-safe
 */
public class SimulatedSensors extends Thread {
	
	private static HashMap<Integer,Boolean> pseudoParkingPositionSensors = new HashMap<Integer,Boolean>();
	private static HashMap<Integer,Boolean> pseudoLandingLaneSensors = new HashMap<Integer,Boolean>();

	private static Fassade fassade;
	
	private int parkposId;
	private int landinglaneId;
	
	public SimulatedSensors(Fassade f){
		fassade = f;
	}

	
	protected Map<Integer,Boolean> getPseudoParkingPositionSensors(){
		return pseudoParkingPositionSensors;
	}
		
	protected Map<Integer,Boolean> getPseudoLandingLaneSensors(){
		return pseudoLandingLaneSensors;
	}
	
	protected void setValues(int parkposId, int landinglaneId){
		this.parkposId = parkposId;
		this.landinglaneId = landinglaneId;
	}
	
	@Override
	public void run(){
		/* Test: set free the parking pos and the landing way sensors after 2 / 4 secs */
		try{
			//System.out.println("[Thread] Pre 1st sleep." + " parkposId: " + this.parkposId);
			Thread.sleep(2000);
			fassade.setIsDirty(true);
			pseudoParkingPositionSensors.put(parkposId, false);	
			//System.out.println("[Thread] Pre 2nd sleep.");
			Thread.sleep(4000);	
			fassade.setIsDirty(true);
			pseudoLandingLaneSensors.put(landinglaneId, false);
		
		} catch(InterruptedException ie){
			ie.printStackTrace();
		}
	}
}
